Hệ thống quản lý ISP trong PHP

1 <?php
2
3     
// Start from getting the hader which contains some settings we need
4     require_once
'includes/headx.php';
5
6     
// require the admins class which containes most functions applied to admins
7     require_once
"includes/classes/admin-class.php";
8
9     $admins =
new Admins($dbh);
10
11     
// check if the form is submitted
12     $page = isset($_GET[
'p' ])?$_GET[ 'p' ]:'';
13
14     
if($page == 'add'){
15             $full_name = $_POST[
'full_name'];
16             $nid = $_POST[
'nid'];
17             $address = $_POST[
'address'];
18             $package = $_POST[
'package'];
19             $conn_location = $_POST[
'conn_location'];
20             $email = $_POST[
'email'];
21             $ip_address = $_POST[
'ip_address'];
22             $conn_type = $_POST[
'conn_type'];
23             $contact = $_POST[
'contact'];
24
25             
if (isset($_POST))
26             {
27
28                 $errors = array();
29                 
// Check if password are the same
30                 
if (!$admins->addCustomer($full_name, $nid, $address, $conn_location, $email, $package, $ip_address, $conn_type, $contact))
31                 {
32                     session::
set('errors', ['Couldn\'t Add New Customer']);
33                 }
else{
34                     session::
set('confirm', 'New customer added successfully!');
35                 }
36             }
37     }
else if($page == 'del'){
38         $id = $_POST[
'id'];
39         
if (!$admins->deletecustomer($id))
40         {
41             echo
"Sorry Data could not be deleted !";
42         }
else {
43             echo
"Well! You've successfully deleted a product!";
44         }
45
46     }
else if($page == 'edit'){
47         $id = $_POST[
'id'];
48         $full_name = $_POST[
'full_name'];
49         $nid = $_POST[
'nid'];
50         $address = $_POST[
'address'];
51         $conn_location = $_POST[
'conn_location'];
52         $email = $_POST[
'email'];
53         $package = $_POST[
'package'];
54         $ip_address = $_POST[
'ip_address'];
55         $conn_type = $_POST[
'conn_type'];
56         $contact = $_POST[
'contact'];
57         
if (!$admins->updateCustomer($id, $full_name, $nid, $address, $conn_location, $email, $package, $ip_address, $conn_type, $contact))
58         {
59             
//echo "$id $customername $email $full_name $address $contact";
60             echo
"Sorry Data could not be Updated !";
61         }
else {
62             $commons->redirectTo(SITE_PATH.
'customers.php');
63         }
64
65     }
else{
66         $customers = $admins->fetchCustomer();
67         
if (isset($customers) && sizeof($customers) > 0) {
68             
foreach ($customers as $customer){
69                 $packageInfo = $admins->getPackageInfo($customer->package_id);
70                 $package_name = $packageInfo->name;
71                  ?>
72                 <tr>
73                     <td scope=
"row"><?=$customer->id ?></td>
74                     <td>
75                         <button type=
"button" id="edit" class="btn btn-success btn-sm" data-toggle="modal" data-target="#edit-<?=$customer->id?>">EDIT</button>
76                         <div
class="fade modal" id="edit-<?=$customer->id?>">
77                             <div
class="modal-dialog" role="document">
78                                 <div
class="modal-content">
79                                     <div
class="modal-header">
80                                         <button type=
"button" class="close" data-dismiss="modal">×</button>
81                                         <h4>Edit Details</h4>
82                                     </div>
83                                     <form method=
"POST">
84                                         <div
class="modal-body">
85                                             <!-- The
async form to send and replace the modals content with its response -->
86                                             <!-- form content -->
87                                             <input type=
"hidden" id="<?=$customer->id ?>" value="<?=$customer->id?>">
88
89                                             <div
class="form-group has-success">
90                                                 <label
for="name">Full Name</label>
91                                                 <input type=
"text" class="form-control" id="fnm-<?=$customer->id?>" value="<?=$customer->full_name?>" required>
92                                             </div>
93                                             <div
class="form-group">
94                                                 <label
for="nid">NID</label>
95                                                 <input type=
"text" class="form-control" id="nid-<?=$customer->id?>" value="<?=$customer->nid?>" required>
96                                             </div>
97                                             <div
class="form-group">
98                                                 <label
for="address">Address</label>
99                                                 <input type=
"text" class="form-control" id="ad-<?=$customer->id?>" value="<?=$customer->address?>" required>
100                                             </div>
101                                             <div
class="form-group">
102                                             <label
for="package">Select Package</label>
103                                                 <
select class="form-control form-control-sm" name="package" id="pk-<?=$customer->id?>">
104                                                 <option
value='<?=$customer->package_id?>'><?=$package_name?></option>
105                                                 <?php
106                                                     $packages = $admins->getPackages();
107                                                     
if (isset($packages) && sizeof($packages) > 0){
108                                                         
foreach ($packages as $package) { ?>
109                                                         <option
value='<?=$package->id?>'><?=$package->name?></option>
110                                                 <?php }} ?>
111                                                 </
select>
112                                             </div>
113                                             <div
class="form-group">
114                                                 <label
for="ip">IP Address</label>
115                                                 <input type=
"text" class="form-control" id="ip-<?=$customer->id?>" value="<?=$customer->ip_address?>" required>
116                                             </div>
117                                             <div
class="form-group">
118                                                 <label
for="contact">Contact</label>
119                                                 <input type=
"text" class="form-control" id="con-<?=$customer->id?>" value="<?=$customer->contact?>" required>
120                                             </div>
121                                             <div
class="form-group">
122                                                 <label
for="conlocation">Connection Location</label>
123                                                 <input type=
"text" class="form-control" id="conn_loc-<?=$customer->id?>" value="<?=$customer->conn_location?>" required>
124                                             </div>
125                                             <div
class="form-group">
126                                                 <label
for="type">Connection Type</label>
127                                                 <input type=
"text" class="form-control" id="ct-<?=$customer->id?>" value="<?=$customer->conn_type?>" required>
128                                             </div>
129                                             <div
class="form-group">
130                                                 <label
for="email">Email</label>
131                                                 <input type=
"text" class="form-control" id="em-<?=$customer->id?>" value="<?=$customer->email?>" required>
132                                             </div>
133                                         </div>
134                                         <div
class="modal-footer">
135                                             <button type=
"submit" onclick="updateData(<?=$customer->id?>)" class="btn btn-primary">Update</button>
136                                             <a href=
"#" class="btn btn-warning" data-dismiss="modal">Cancel</a>
137                                         </div>
138                                     </form>
139                                 </div>
140                             </div>
141                         </div>
142                         <button type=
"submit" id="delete" onclick="delData(<?=$customer->id ?>)" class="btn btn-warning btn-sm">DELETE</button>
143                     </td>
144                     <td
class="search"><?=$customer->full_name?></td>
145                     <td
class="search"><?=$customer->nid?></td>
146                     <td
class="search"><?=$customer->address?></td>
147                     <td
class="search"><?=$package_name?></td>
148                     <td
class="search"><?=$customer->ip_address?></td>
149                     <td
class="search"><?=$customer->email?></td>
150                     <td
class="search"><?=$customer->conn_type?></td>
151                     <td
class="search"><?=$customer->contact?></td>
152                 </tr>
153             <?php
154             }
155         }
156     }
157 ?>


Gõ tìm kiếm nhanh...